//
//  CameraManager_PhotoCapture.swift
//  Camera
//
//  Created by Hammer King on 2025/4/1.
//

import Foundation
import AVFoundation

extension CameraManager: AVCapturePhotoCaptureDelegate {
    
    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
        if let error = error {
            delegate?.capturePhoto(data: nil, error: error)
            return
        }
        
        guard let imageData = photo.fileDataRepresentation() else {
            delegate?.capturePhoto(data: nil, error: NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey: "Photo data not available"]))
            return
        }
        delegate?.capturePhoto(data: imageData, error: nil)
    }
    
}
